package micro86.operation;

import micro86.engine.Memory;
import micro86.engine.MemoryException;
import micro86.engine.State;
import micro86.engine.parametres.IntParameter;

/**
 * Created with IntelliJ IDEA.
 * User: alar
 * Date: 28.03.13
 * Time: 18:32
 * To change this template use File | Settings | File Templates.
 */
public class MovToMemory implements IOperation{
    IntParameter cellNum;
    IntParameter value;

    public MovToMemory(IntParameter cellNum, IntParameter value){
        this.cellNum = cellNum;
        this.value = value;
    }

    @Override
    public void execute(State state, Memory memory) throws IOperationException{
        int destinationValue = value.get(state);
        int cell = cellNum.get(state);
        try {
            memory.setValue(cell, destinationValue);
        } catch (MemoryException e) {throw new IOperationException(e.toString());}

        state.incIP();
    }

}
